package org.istt.dao.hibernate;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.istt.dao.AttachFileDetailDao;
import org.istt.domain.AttachFileDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.stereotype.Repository;

/**
 * @author NDTHO
 */
@Repository(value = "attachFileDetailDao")
public class AttachFileDetailDaoHibernate extends BaseDaoHibernate<AttachFileDetail, Long> implements AttachFileDetailDao {
	Log logger = LogFactory.getLog(AttachFileDetailDaoHibernate.class);

	@Autowired
	public AttachFileDetailDaoHibernate(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	public AttachFileDetail getAttachFileDetail(Long id) {
		AttachFileDetail attachFileDetail = findById(id, false);
		if (attachFileDetail == null) {
			throw new ObjectRetrievalFailureException(AttachFileDetail.class, id);
		}
		return attachFileDetail;
	}

	@Override
	public void removeAttachFileDetail(Long attachFileDetailId) {
		AttachFileDetail attDetail = getAttachFileDetail(attachFileDetailId);
		attDetail.setFile(null);
		
		makeTransient(attDetail);
	}

	@Override
	public AttachFileDetail getById(Long attachFileDetailId) {
		return getAttachFileDetail(attachFileDetailId);
	}
}
